home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FileUtils.h
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <11> 4/5/95 HDA fix DoGet's check for folders. Now checks for ioDirMask
- <10> 1/11/95 TMH added Write(StringPtr pascalString)
- <8> 10/20/94 TMH added Exists()
- <7> 10/14/94 TMH some file id methods
- <6> 10/13/94 TMH added Delete()
- <5> 10/6/94 TMH SetFSSpec does not return an error
- <4> 10/3/94 TMH added SetType and SetCreator
- <3> 9/30/94 TMH added CFolderIterator
- <2> 9/27/94 TMH added CFSSpec, CFolder and CFile descend from CFSSpec
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <4> 9/20/94 TMH added overloaded Write(char* str) method
- <3> 9/9/94 TMH more methods for
- <2> 6/14/94 TMH methods for opening closeing, writing
- 4/18/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
-
- #ifndef __FileUtils__
- #define __FileUtils__
-
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __FILES__
- #include "Files.h"
- #endif
-
- #ifndef __FOLDERS__
- #include "Folders.h"
- #endif
-
- #ifndef __PASCALSTRING__
- #include "PascalString.h"
- #endif
-
- #ifndef __MEMORY__
- #include "Memory.h"
- #endif
-
- class CRString32;
-
- const kDataExceedsBufLen = 100;
-
-
- //--------------------------------------
- // C F S S p e c
- //--------------------------------------
-
- class CFSSpec {
- public:
-
- CFSSpec() {memset(&fFSSpec,0,sizeof(FSSpec));}
- CFSSpec(HFileInfo* infoPB);
- CFSSpec(short vRefNum,long parentdDirID,StringPtr name);
- CFSSpec(short vRefNum,long parentdDirID,char* name);
-
- void SetFSSpec(short vRefNum,long dirID,StringPtr name);
- void SetName(StringPtr newName) { BlockMove(newName,fFSSpec.name,newName[0]+1); }
-
- OSErr GetCatInfo(CInfoPBRec& cInfo);
- OSErr SetCatInfo(CInfoPBRec& cInfo);
-
- StringPtr NamePtr() { return (StringPtr) &fFSSpec.name; }
- short VRefNum() { return fFSSpec.vRefNum; }
- long ParID() { return fFSSpec.parID; }
-
- FSSpec fFSSpec;
-
- };
-
- //--------------------------------------
- // C F i l e
- //--------------------------------------
-
- class CFile : public CFSSpec {
- public:
- CFile();
- CFile(short vRefNum,long parentdDirID,StringPtr name);
- CFile(short vRefNum,long parentdDirID,char* name);
- CFile(HFileInfo* infoPB);
-
- //-----------------
- // Accessors
- //-----------------
-
-
- OSErr GetPhysicalSize(long& dataSize, long& rsrcSize);
- OSErr GetFileInfo(HParamBlockRec& pb);
-
-
- long GetPosition();
- long GetSize();
-
- void SetPosition(long newPosition);
- void SetToStartOfLine(char lineTerminator=0x0d);
-
- Boolean Exists();
- Boolean IsOpen() { return fRefNum != 0; }
-
-
- OSErr Delete();
- // Create
-
-
- OSErr Create(OSType fileCreator, OSType fileType);
- OSErr Open(char permission);
- OSErr OpenResourceFork(char permission);
- OSErr Close();
-
-
- // Writing
-
-
- OSErr Write(void* data,long dataLen);
- OSErr Write(char* c); // write 'C' string.
- OSErr Write(StringPtr pascalString); // write Pascal string.
-
-
- // Reading
-
-
- OSErr Read(void* data,long* dataLen);
- char ReadByte();
- long ReadLine(char* lineBuf,long maxChars,char lineTerminator=0x0d);
- long ReadUntilChar(void* buf,long* dataLen,char tillChar);
-
-
- // File Info
-
- long GetCreationDate();
- long GetModificationDate();
-
- OSErr SetType(OSType fileType);
- OSErr SetCreator(OSType fileCreator);
- OSErr SetCreatorAndType(OSType fileCreator,OSType fileType);
-
-
- OSErr GetFileID(long* fileID );
-
- private:
- short fRefNum; // != 0 when file open
- };
-
-
- //--------------------------------------
- // C F o l d e r
- //--------------------------------------
- class CFolder : public CFSSpec {
- public:
- CFolder() { fDirID = 0; };
- CFolder(OSType folderType);
- CFolder(short vRefNum,long parentdDirID,StringPtr name);
- CFolder(short vRefNum,long parentdDirID,char* name);
-
- OSErr CreateFolder();
- OSErr GetDirInfo(DirInfo& dirInfoPB);
- long DirID() { return fDirID; };
-
- long fDirID;
-
- OSType fFolderType;
- };
-
-
- //----------------------------------
- // C F o l d e r I t e r a t o r
- //-----------------------------------
-
- // Use this to iterate over all the files in a
- // folder.
-
- class CFolderIterator {
- public:
- enum ItemFilter {
- kFilesAndFolders = 0,
- kFilesOnly,
- kFoldersOnly
- };
- CFolderIterator(CFolder& folder,CFolderIterator::ItemFilter itemFilter);
- HFileInfo* FirstFile();
- Boolean More() { return fCatInfo->ioResult == 0; };
- HFileInfo* NextFile();
- OSErr IOResult() { return fCatInfo->ioResult; }
- private:
- void DoGet();
-
-
- short fVRefNum;
- long fDirID;
- CInfoPBRec fCatInfoPB;
- HFileInfo* fCatInfo;
- Str255 fNameBuf;
- short fIndex;
-
- ItemFilter fItemFilter;
- };
-
-
- //------------------------------------
-
- extern OSErr SearchFolder(short vRefNum, long dirID, Boolean (*DoEachFile)(HFileInfo* filePB,void* refCon), void* refCon );
- extern Boolean FindAnyFile(HFileInfo* filePB,void* refCon);
- extern OSErr FindFolder(CFolder* folder);
- extern Boolean FindFileByName(short vRefNum, long dirID, CFile* fileToFind);
-
- extern Boolean __FindFolder(HFileInfo* filePB,void* refCon);
-
- extern OSErr FocHFSHeirarchy(OSType folderParentType,char* pathName,CFolder& lastChild);
- extern OSErr FocHFSHeirarchyFromResource(short resId,CFolder& lastChild);
-
- extern int ParseHFSPath(char* pathName,char** folderList);
-
- OSErr ExchangeFileIDs(CFile& srcFile,CFile& destFile);
-
- #endif __FileUtils__
-